function to(url, param) {
  wx.navigateTo({
    url: url + formatParam(param)
  })
}

function redirect(url, param) {
  wx.redirectTo({
    url: url + formatParam(param)
  })
}

function switchTab(url) {
  wx.switchTab({
    url: url
  })
}

function formatParam(param) {
  if(param) {
    let strs = []
    for (let key in param) {
      strs.push(key + '=' + param[key])
    }
    return '?' + strs.join('&')
  }
  return "";
}

function toRoom(uid) {
  to('/pages/room/room', {uid})
}

function toRegister() {
  to('/pages/login/login')
}

function toHome() {
  switchTab('/pages/index/index')
}

function toOpenMyRoom() {
  to('/pages/editRoom/editRoom')
}

export const router = {
  to,
  toRoom,
  toRegister,
  toHome,
  toOpenMyRoom
}
